package com.xuhj.service;

import com.xuhj.pojo.Dept;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class DeptClientHystrix implements FallbackFactory {
/**
 *
 * 对于整个类进行服务降级，对那个controller就需要返回哪个类型的对象，
 * 比如我们需要对DeptClientService类进行降级处理，那我们就要返回DeptClientService类型的对象
*/
    @Override
    public DeptClientService create(Throwable throwable) {
        return new DeptClientService() {
            @Override
            public Dept queryById(Long id) {
                return new Dept().setDeptno(id).setDname("此服务开启了服务降级，暂不处理请求，请稍后重试");
            }

            @Override
            public List<Dept> queryAll() {
                return null;
            }

            @Override
            public Boolean addDept(Dept dept) {
                return null;
            }
        };
    }
}
